package com.yxx.manager;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.PreDestroy;

/**
 * 确保应用退出时能关闭后台线程
 * 停止线程异步任务执行器
 * @author yuxiangxun
 * @date 2025/2/14
 * @apiNote
 */
@Component
public class ShutdownManager {
    private static final Logger logger = LoggerFactory.getLogger(ShutdownManager.class);

    @PreDestroy
    public void destory(){
        shutdownAsyncManager();
    }

    /**
     * 停止异步执行任务（停止异步任务执行器）
     */
    private void shutdownAsyncManager(){
        try {
            logger.info("===关闭有台任务任务线程池===");
            AsyncManager.getInstance().shutdown();
        }catch (Exception e){
            logger.error(e.getMessage());
        }
    }
}
